package com.gohome.gohomechat.ui.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.gohome.gohomechat.R;
import com.gohome.gohomechat.ui.fragment.FragmentFactory;

/**
 * Created by dllo on 16/3/1.
 */
public class MainViewPagerAdapter extends FragmentPagerAdapter {
    private Context context;
    private String[] tabTitles = {"会话", "通讯录", "其他", "设置"};
    private int[] tabPicture={R.drawable.tab_session_selector,R.drawable.tab_address_selector
    ,R.drawable.tab_other_selector,R.drawable.tab_set_selector};

    public MainViewPagerAdapter(FragmentManager fm, Context context) {
        super(fm);
        this.context = context;
    }

    @Override
    public Fragment getItem(int position) {
        return FragmentFactory.createFragment(position);
    }

    @Override
    public int getCount() {
        return 4;
    }

    /**
     * 自定义实现底部导航
     * 用于显示文字和图片的组合
     */
    public View getTabView(int position) {
        View view = LayoutInflater.from(context).inflate(R.layout.tablayout_tabitem, null);
        ImageView tab_image = (ImageView) view.findViewById(R.id.tab_image);
        TextView tab_item = (TextView) view.findViewById(R.id.tab_item);
        tab_item.setText(tabTitles[position]);
        tab_image.setImageResource(tabPicture[position]);

        return view;
    }
}
